package main

import "fmt"

func main() {
	arr := [8]int{1, 2, -10, 5, 0, 9, 100, -20}
	fmt.Println(arr)
	//数组作为参数传递是值传递
	bubbleSort(&arr)
	fmt.Println(arr)

	arr1 := []int{1, 2, -10, 5, 0, 9, 100, -20}
	//切片作为参数传递是引用传递
	selectSort(arr1)
	fmt.Println("arr1=", arr1)
}

//冒泡排序
func bubbleSort(arr *[8]int) {
	arrlen := len(arr) - 1

	for i := 0; i < arrlen; i++ {
		for j := 0; j < arrlen-i; j++ {
			if arr[j] > arr[j+1] {
				arr[j], arr[j+1] = arr[j+1], arr[j]
			}
		}
	}
	fmt.Printf("%T\n", arr)
	fmt.Println(*arr)
}

//选择排序
func selectSort(arr []int) {
	count := len(arr)

	for i := 0; i < count-1; i++ {
		for j := i + 1; j < count; j++ {
			if arr[i] > arr[j] {
				arr[i], arr[j] = arr[j], arr[i]
			}
		}
	}
	fmt.Println(arr)
}
